﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace Rex.Assignment.EFCore.Context
{
    /// <summary>
    /// DbContextFactory
    /// </summary>
    /// <remarks>
    /// @创 建 者：Rex
    /// @创建日期：2021/2/21 13:43:51
    /// </remarks>
    public class DbContextFactory : IDesignTimeDbContextFactory<SysUserContext>
    {
        public SysUserContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<SysUserContext>();

            // 注：数据库连接字符串建议放在配置文件中
            string connectionStr = "server=127.0.0.1;port=3306;database=rex_assignment;uid=root;pwd=abc12345;CharSet=utf8";
            
            builder.UseMySQL(connectionStr);

            return new SysUserContext(builder.Options);
        }

    }
}
